package com.gpipe.tools;

import com.gpipe.properties.InputProperties;

import java.text.ParseException;

/**
 * Created by admin on 2017/8/17.
 */
public class ODList {
    private String date;
    private String timePeriod;
    private String nbr;
    private String beginTime;
    private String arriveTime;
    private String lacCiO;
    private String lacCiD;
    private String commuting;

    public ODList(String date,String timePeriod,String nbr, String beginTime, String arriveTime, String lacCiO, String lacCiD) {
        this.date=date;
        this.timePeriod=timePeriod;
        this.nbr = nbr;
        this.beginTime = beginTime;
        this.arriveTime = arriveTime;
        this.lacCiO = lacCiO;
        this.lacCiD = lacCiD;


    }

    public String getCommuting() {
        return commuting;
    }

    public void setCommuting(String commuting) {
        this.commuting = commuting;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTimePeriod() {
        return timePeriod;
    }

    public void setTimePeriod(String timePeriod) {
        this.timePeriod = timePeriod;
    }

    public int getSpeed(){
        //单位km/h
        long duration = getDuration();
        long distance = getDistance();

        if(duration==-1||duration==0||distance==-1){
            return 0;
        }else{
            return (int) Math.round(distance/duration*3.6);
        }
    }

    public long getDuration() {
        //单位秒
        if (GpipeInit.isNotEmpty(this.beginTime) && GpipeInit.isNotEmpty(this.arriveTime)) {
            return Math.round(GpipeInit.duration(this.arriveTime, this.beginTime));
        } else
            return -1;
    }

    public long getDistance() {
        BaseAreaModel bamO = InputProperties.baseArea.get(lacCiO);
        BaseAreaModel bamD = InputProperties.baseArea.get(lacCiD);
//        try {
            if (bamO!= null && bamD!= null) {
                return Math.round(GpipeInit.getDistance(bamO.getLongitude(), bamO.getLatitude(), bamD.getLongitude(), bamD.getLatitude()));
            } else {
                return -1;
            }
//        } catch (NullPointerException e) {
//            System.out.println();
//        }
//        return Double.valueOf(-1);
    }

    public static void main(String[] args) {
        ODList lll = new ODList("20170707","0000-0015","13302333371","20170707234538","20170707234555","lac1","lac2");
        long dd  = lll.getDuration();
        System.out.println(dd);
    }

    public String getNbr() {
        return nbr;
    }

    public void setNbr(String nbr) {
        this.nbr = nbr;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getArriveTime() {
        return arriveTime;
    }

    public void setArriveTime(String arriveTime) {
        this.arriveTime = arriveTime;
    }

    public String getLacCiO() {
        return lacCiO;
    }

    public void setLacCiO(String lacCiO) {
        this.lacCiO = lacCiO;
    }

    public String getLacCiD() {
        return lacCiD;
    }

    public String getLacCiOD() {
        return lacCiO+"|"+lacCiD;
    }

    public void setLacCiD(String lacCiD) {
        this.lacCiD = lacCiD;
    }
}
